package baseClass;

import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.util.ArrayList;

public class HistoryTable {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty age = new SimpleStringProperty();
    private SimpleStringProperty sex = new SimpleStringProperty();
    private SimpleStringProperty idNumber = new SimpleStringProperty();
    private SimpleStringProperty numberOfPeople = new SimpleStringProperty();
    private SimpleStringProperty roomNumber = new SimpleStringProperty();
    private SimpleStringProperty dateCheckIn = new SimpleStringProperty();
    private SimpleStringProperty dateCheckOut = new SimpleStringProperty();

    public HistoryTable(History history){
        String[] properties = history.getHistoryInformation();
        name.set(properties[0]);
        age.set(properties[1]);
        sex.set(properties[2]);

        //隐私保护
        StringBuilder idNum = new StringBuilder(properties[3]);
        idNumber.set(idNum.replace(3,17, "**************").toString());

        numberOfPeople.set(properties[4]);
        roomNumber.set(properties[5]);
        if(properties[6] != null) {
            dateCheckIn.set(properties[6]);
        }
        if(properties[7] != null) {
            dateCheckOut.set(properties[7]);
        }
    }

    public static ObservableList<HistoryTable> getHistoryTable(ArrayList<History> histories){
        if(histories == null){//为空则直接返回
            return null;
        }

        ObservableList<HistoryTable> historyTable = FXCollections.observableArrayList();
        for (History history : histories) {
            historyTable.add(new HistoryTable(history));
        }
        return historyTable;
    }

    public String getName(){
        return name.get();
    }

    public String getAge(){
        return age.get();
    }

    public String getSex(){
        return sex.get();
    }

    public String getIdNumber(){
        return idNumber.get();
    }

    public String getNumberOfPeople(){
        return numberOfPeople.get();
    }

    public String getRoomNumber(){
        return roomNumber.get();
    }

    public String getDateCheckIn(){
        return dateCheckIn.get();
    }

    public String getDateCheckOut(){
        return dateCheckOut.get();
    }
}
